<?php

$wishId=$_GET['editwish'];
$proId = $_GET['proid'];

if($_SESSION['user_id_sess']=="") {
	echo "<script type='text/javascript'> window.location='index.php?signin'; </script>";
}

require_once "includes/class/product_management.class.php";

$productObject = new product_management;
$products = $productObject->getProductById($proId);

$productOwner=$products['posted_by'];	

$productName=$products['product_name'];	
$productDesc=$products['product_description'];
$productCategory=$products['category_id'];
$productThumbnail=$products['product_thumbnail'];	
$productImage=$products['product_image'];
$productSample=$products['product_sample'];
$productPrice=$products['product_price'];
$bargainAmount=$products['bargain_amount'];
$postedDate=$products['posted_date'];
$bargainDate = $products['bargain_duration'];
$timeLeft = getRemainingTime($bargainDate); 
if($productImage=="") { 
	$productImage="images/no_image.gif"; $productThumbnail="images/no_image.gif";
	$productSample="images/no_image.gif"; 
}		  
$catInfo=getCategory($productCategory);

$userid=$_SESSION['user_id_sess'];

if(!empty($_POST['hidEditWishlist'])) {
	if($proId!="" && $userid!="") {			
		
			$wprice = $_POST['wish_price'];
			$wdesc = $_POST['wish_description'];
			$sql="UPDATE tbl_wishlist set wish_price='$wprice', wish_desc='$wdesc' WHERE wishlist_id='$wishId'";
			$rst=mysql_query($sql);
			if($rst) { 
				echo "<script type='text/javascript'> window.location='index.php?wlist'; </script>";
			}
			else { $msg = "<div id='err-msg'>Error on updating your wishlist.</div>"; }
				
	}	
}

$sqlSelWish = "SELECT * FROM tbl_wishlist where wishlist_id='$wishId'";
$rstSelWish = mysql_query($sqlSelWish);
$rowSelWish = mysql_fetch_array($rstSelWish);

			
?>

<table width="100%" border="0">
  <tr>
    <td class="contentHeader"><h2>Edit wishlist </h2></td>
  </tr>
  <tr>
    <td>
		<div style="border:1px solid #CCC;">
		   <table width='100%' border='0' align='center' cellspacing='0'>
				<tr>						        
					 <td width="16%" rowspan="2" style='vertical-align:top; padding:5px;'> <img src="<?php echo $productThumbnail; ?>"> </td>
					 <td width="44%" style='vertical-align:top; padding:5px;'> <?php echo "$productName";?> </td>
					 <td width="11%" style='vertical-align:top; padding:5px;'> <strong>Price </strong> <br> <br> $<?php echo number_format($productPrice,2); ?> </td>
					 <td width="10%" style='vertical-align:top; padding:5px;'> <strong>Shipping</strong> <br> <br> -- </td>
					 <td width="19%" style='vertical-align:top; padding:5px;'> <strong>Time left </strong><br> <br> <?php echo $timeLeft; ?> </td>
				</tr>
				<tr>
				  <td height="58"></td>
				  <td colspan="3" align="center" style='vertical-align:top; padding:5px;'></td>
				</tr>
		  </table>
		</div>
		<br>
		<div id="panel">
			<form name="frmEditWishlist" id="frmEditWishlist" action="" method="post">
				<input type="hidden" name="hidEditWishlist" id="hidEditWishlist">
				<table width="100%" align="center" border="0">
					<tr>
					  <td>&nbsp;</td>
					  <td colspan="2" align="center">
					  	<?php
							if(!empty($msg)) {
								echo $msg;
							}
						?>
					  </td>
					  <td>&nbsp;</td>
				  </tr>
					
					<tr>
						<td width="1%">&nbsp;</td>
						<td width="18%"><strong>Price</strong></td>
						<td width="80%"><input type="text" name="wish_price" id="wish_price" value="<?php echo $rowSelWish['wish_price']; ?>"></td>
						<td width="1%">&nbsp;</td>
					</tr>
					<tr>
					  <td>&nbsp;</td>
					  <td valign="top"><strong>Description</strong></td>
					  <td><textarea name="wish_description" cols="40" rows="8" id="wish_description"><?php echo $rowSelWish['wish_desc']; ?></textarea></td>
					  <td>&nbsp;</td>
				  </tr>
					<tr>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
				  </tr>
					<tr>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
					  <td><input onClick="funEditWishlist(<?php echo $wishId; ?>)" type="button" name="btnAddWishlist" id="btnAddWishlist" value="Update wishlist"></td>
					  <td>&nbsp;</td>
				  </tr>
				</table>
			</form>
		  <br>
		</div>
		
	</td>
  </tr>
</table> 	
		


